﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.Connection;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.DAL
{
    class ChiTietHDNhap
    {
        private dbConnection Conn;

        public ChiTietHDNhap()
        {
            Conn = new dbConnection();
        }

        public DataTable SelectAll()
        {
            return Conn.excuteSelectProcedureQuery("SelectAll_ChiTietHDNhap");
        }

        public DataTable SelectID(string MaHDNhap)
        {
            SqlParameter[] SqlPara = new SqlParameter[1];
            SqlPara[0] = new SqlParameter("@MaHDNhap", SqlDbType.NVarChar, 10);
            SqlPara[0].Value = Convert.ToString(MaHDNhap);
            return Conn.excuteSelectProcedureQuery("SelectID_ChiTietHDNhap", SqlPara);
        }

        public bool Insert(string MaHDNhap, string MaSP, int SoLuong, int DonGiaNhap)
        {
            SqlParameter[] SqlPara=new SqlParameter[4];
            SqlPara[0] = new SqlParameter("@MaHDNhap",SqlDbType.NVarChar,10);
            SqlPara[0].Value = Convert.ToString(MaHDNhap);
            SqlPara[1] = new SqlParameter("@MaSP",SqlDbType.NVarChar,10);
            SqlPara[1].Value = Convert.ToString(MaSP);
            SqlPara[2] = new SqlParameter("@SoLuong",SqlDbType.Int);
            SqlPara[2].Value = SoLuong;
            SqlPara[3] = new SqlParameter("@DonGiaNhap",SqlDbType.Int);
            SqlPara[3].Value = DonGiaNhap;
            return Conn.executeInsertProcedureQuery("Insert_ChiTietHDNhap",SqlPara);
        }

        public bool Update(string MaHDNhap, string MaSP, int SoLuong, int DonGiaNhap)
        {
            SqlParameter[] SqlPara = new SqlParameter[4];
            SqlPara[0] = new SqlParameter("@MaHDNhap",SqlDbType.NVarChar,10);
            SqlPara[0].Value = Convert.ToString(MaHDNhap);
            SqlPara[1] = new SqlParameter("@MaSP", SqlDbType.NVarChar, 10);
            SqlPara[1].Value = Convert.ToString(MaSP);
            SqlPara[2] = new SqlParameter("@SoLuong", SqlDbType.Int);
            SqlPara[2].Value = SoLuong;
            SqlPara[3] = new SqlParameter("@DonGiaNhap", SqlDbType.Int);
            SqlPara[3].Value = DonGiaNhap;
            return Conn.executeUpdateProcedureQuery("Update_ChiTietHDNhap",SqlPara);
        }

        public bool Delete(string MaHDNhap)
        { 
            SqlParameter[] SqlPara=new SqlParameter[1];
            SqlPara[0] = new SqlParameter("@MaHDNhap",SqlDbType.NVarChar,10);
            SqlPara[0].Value = Convert.ToString(MaHDNhap);
            return Conn.executeDeleteProcedureQuery("Delete_ChiTietHDNhap",SqlPara);
        }
    }
}
